package evocarcassonne.tileseteditor.ui.swing;

import evocarcassonne.core.utils.Card;
import evocarcassonne.tileseteditor.managers.MainManager;
import evocarcassonne.tileseteditor.managers.TileManager;
import evocarcassonne.tileseteditor.ui.swing.components.LinksTable;
import evocarcassonne.tileseteditor.ui.swing.components.TileNode;
import evocarcassonne.tileseteditor.ui.swing.components.TilesTree;
import evocarcassonne.tileseteditor.ui.swing.components.ZoneTypeComboBox;
import evocarcassonne.tileseteditor.ui.swing.panels.zones.CityPanel;
import evocarcassonne.tileseteditor.ui.swing.panels.zones.MeadowPanel;
import evocarcassonne.tileseteditor.ui.swing.panels.zones.RoadPanel;
import net.miginfocom.swing.MigLayout;

import javax.swing.border.TitledBorder;

public class MainForm extends javax.swing.JFrame {

    final MainManager mainManager;
    private int indexTile = 0;

    public MainForm() {
        initComponents();

        ConnectionsManager.init();

        mainManager = new MainManager(this, new TileDrawer(drawPanel), (LinksTable) jTable1);
    }

    public void clearConns() {
        connPanel.removeAll();
    }

    public void addConn(int... conns) {

        MigLayout layout = new MigLayout("wrap 2");
        connPanel.setLayout(layout);

        for (int conn : conns) {
            connPanel.add(ConnectionsManager.get(conn));
        }

        connPanel.revalidate();
        connPanel.repaint();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jMenuItem1 = new javax.swing.JMenuItem();
        jSplitPane2 = new javax.swing.JSplitPane();
        jPanel2 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jSplitPane1 = new javax.swing.JSplitPane();
        tileSetPanel = new javax.swing.JPanel();
        addTileButton = new javax.swing.JButton();
        removeTileButton = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        tilesTree = new TilesTree();
        jPanel4 = new javax.swing.JPanel();
        paramsTile = new javax.swing.JPanel();
        jPanel6 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        cb_north = new ZoneTypeComboBox(Card.N);
        jLabel2 = new javax.swing.JLabel();
        cb_east = new ZoneTypeComboBox(Card.E);
        jLabel3 = new javax.swing.JLabel();
        cb_south = new ZoneTypeComboBox(Card.S);
        jLabel4 = new javax.swing.JLabel();
        cb_west = new ZoneTypeComboBox(Card.W);
        showSouthPanel = new javax.swing.JButton();
        showEastPanel = new javax.swing.JButton();
        showWestPanel = new javax.swing.JButton();
        jToggleButton1 = new javax.swing.JToggleButton();
        connPanel = new javax.swing.JPanel();
        drawPanel = new javax.swing.JPanel();
        resetTileButton = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTable1 = new LinksTable();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        zoneTypePanel = new javax.swing.JPanel();

        jMenuItem1.setText("jMenuItem1");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("EvoCarcassonne - TileEditor");

        jSplitPane2.setBorder(null);
        jSplitPane2.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
        jSplitPane2.setResizeWeight(0.8);

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)), "Messages"));

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jScrollPane2.setViewportView(jTextArea1);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 794, Short.MAX_VALUE)
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 36, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jSplitPane2.setBottomComponent(jPanel2);

        jSplitPane1.setBorder(null);

        tileSetPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)), "Tile Set"));

        addTileButton.setText("Add");
        addTileButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addTileButtonActionPerformed(evt);
            }
        });

        removeTileButton.setText("Remove");
        removeTileButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removeTileButtonActionPerformed(evt);
            }
        });

        tilesTree.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tilesTreeMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(tilesTree);

        javax.swing.GroupLayout tileSetPanelLayout = new javax.swing.GroupLayout(tileSetPanel);
        tileSetPanel.setLayout(tileSetPanelLayout);
        tileSetPanelLayout.setHorizontalGroup(
            tileSetPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, tileSetPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(tileSetPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, tileSetPanelLayout.createSequentialGroup()
                        .addComponent(addTileButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(11, 11, 11)
                        .addComponent(removeTileButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING))
                .addContainerGap())
        );
        tileSetPanelLayout.setVerticalGroup(
            tileSetPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(tileSetPanelLayout.createSequentialGroup()
                .addGroup(tileSetPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(addTileButton)
                    .addComponent(removeTileButton))
                .addGap(10, 10, 10)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 896, Short.MAX_VALUE)
                .addContainerGap())
        );

        jSplitPane1.setLeftComponent(tileSetPanel);

        paramsTile.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)), "Tile XXX"));
        paramsTile.setAutoscrolls(true);

        jPanel6.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jLabel1.setText("North :");

        jLabel2.setText("East :");

        jLabel3.setText("South :");

        jLabel4.setText("West :");

        showSouthPanel.setText(">>");
        showSouthPanel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                showSouthPanelActionPerformed(evt);
            }
        });

        showEastPanel.setText(">>");
        showEastPanel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                showEastPanelActionPerformed(evt);
            }
        });

        showWestPanel.setText(">>");
        showWestPanel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                showWestPanelActionPerformed(evt);
            }
        });

        jToggleButton1.setText(">>");
        jToggleButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jToggleButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(cb_east, javax.swing.GroupLayout.Alignment.TRAILING, 0, 261, Short.MAX_VALUE)
                    .addComponent(cb_north, javax.swing.GroupLayout.Alignment.TRAILING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(cb_south, javax.swing.GroupLayout.Alignment.TRAILING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(cb_west, javax.swing.GroupLayout.Alignment.TRAILING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(showSouthPanel)
                            .addComponent(showEastPanel, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addComponent(showWestPanel, javax.swing.GroupLayout.Alignment.TRAILING))
                    .addComponent(jToggleButton1, javax.swing.GroupLayout.Alignment.TRAILING))
                .addContainerGap())
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(cb_north, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jToggleButton1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(cb_east, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(showEastPanel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(cb_south, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(showSouthPanel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cb_west, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4)
                    .addComponent(showWestPanel))
                .addContainerGap())
        );

        connPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        connPanel.setMaximumSize(new java.awt.Dimension(300, 200));
        connPanel.setMinimumSize(new java.awt.Dimension(300, 200));
        connPanel.setPreferredSize(new java.awt.Dimension(300, 200));

        javax.swing.GroupLayout connPanelLayout = new javax.swing.GroupLayout(connPanel);
        connPanel.setLayout(connPanelLayout);
        connPanelLayout.setHorizontalGroup(
            connPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );
        connPanelLayout.setVerticalGroup(
            connPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );

        drawPanel.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        drawPanel.setMaximumSize(new java.awt.Dimension(300, 200));
        drawPanel.setMinimumSize(new java.awt.Dimension(300, 200));
        drawPanel.setPreferredSize(new java.awt.Dimension(300, 200));
        drawPanel.setVerifyInputWhenFocusTarget(false);

        javax.swing.GroupLayout drawPanelLayout = new javax.swing.GroupLayout(drawPanel);
        drawPanel.setLayout(drawPanelLayout);
        drawPanelLayout.setHorizontalGroup(
            drawPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );
        drawPanelLayout.setVerticalGroup(
            drawPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 248, Short.MAX_VALUE)
        );

        resetTileButton.setText("Reset");
        resetTileButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                resetTileButtonActionPerformed(evt);
            }
        });

        jButton4.setText("Random");

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jScrollPane3.setViewportView(jTable1);

        jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel5.setText("North");

        jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel6.setText("South");

        jLabel7.setText("West");

        jLabel8.setText("East");

        javax.swing.GroupLayout paramsTileLayout = new javax.swing.GroupLayout(paramsTile);
        paramsTile.setLayout(paramsTileLayout);
        paramsTileLayout.setHorizontalGroup(
            paramsTileLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(paramsTileLayout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addComponent(resetTileButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(20, 20, 20)
                .addComponent(jButton4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(10, 10, 10))
            .addGroup(paramsTileLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(paramsTileLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 389, Short.MAX_VALUE)
                    .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(paramsTileLayout.createSequentialGroup()
                        .addComponent(jLabel7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(drawPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 329, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel8)
                        .addGap(6, 6, 6))
                    .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, paramsTileLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(connPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 389, Short.MAX_VALUE)
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, paramsTileLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel6, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        paramsTileLayout.setVerticalGroup(
            paramsTileLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(paramsTileLayout.createSequentialGroup()
                .addGroup(paramsTileLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(resetTileButton)
                    .addComponent(jButton4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(27, 27, 27)
                .addComponent(connPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 180, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(paramsTileLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(drawPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 252, Short.MAX_VALUE)
                    .addGroup(paramsTileLayout.createSequentialGroup()
                        .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 52, Short.MAX_VALUE))
                    .addComponent(jLabel7, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 253, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        zoneTypePanel.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)), "zoneType"));
        zoneTypePanel.setLayout(new javax.swing.BoxLayout(zoneTypePanel, javax.swing.BoxLayout.LINE_AXIS));

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(paramsTile, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(zoneTypePanel, javax.swing.GroupLayout.DEFAULT_SIZE, 201, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(paramsTile, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(zoneTypePanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        jSplitPane1.setRightComponent(jPanel4);

        jSplitPane2.setLeftComponent(jSplitPane1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jSplitPane2)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jSplitPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 1034, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void addTileButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addTileButtonActionPerformed
        indexTile++;
        ((TilesTree) tilesTree).addObject(indexTile);
        TileManager.addTile(indexTile);

        mainManager.addTile();
    }//GEN-LAST:event_addTileButtonActionPerformed

    private void resetTileButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_resetTileButtonActionPerformed
        mainManager.resetAll();
        ConnectionsManager.resetConnections();
        TileManager.resetLinks();
    }//GEN-LAST:event_resetTileButtonActionPerformed

    private void removeTileButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeTileButtonActionPerformed
        ((TilesTree) tilesTree).removeSelectedObject();

    }//GEN-LAST:event_removeTileButtonActionPerformed

    private void tilesTreeMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tilesTreeMouseClicked

        if (tilesTree.getSelectionPath() == null
                || tilesTree.getSelectionPath().getLastPathComponent() == ((TilesTree) tilesTree).rootNode) {
            return;
        }
        TileNode node = (TileNode) tilesTree.getSelectionPath().getLastPathComponent();
        TileManager.setTile(node.getNumber());

        mainManager.setTileParameters();

    }//GEN-LAST:event_tilesTreeMouseClicked

    private void showEastPanelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showEastPanelActionPerformed
        showCardPanel(Card.E);
    }//GEN-LAST:event_showEastPanelActionPerformed

    private void showSouthPanelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showSouthPanelActionPerformed
        showCardPanel(Card.S);
    }//GEN-LAST:event_showSouthPanelActionPerformed

    private void showWestPanelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_showWestPanelActionPerformed
        showCardPanel(Card.W);
    }//GEN-LAST:event_showWestPanelActionPerformed

    private void jToggleButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton1ActionPerformed
        
       
        showCardPanel(Card.N);
    }//GEN-LAST:event_jToggleButton1ActionPerformed

    public void showCardPanel(int card) {

        zoneTypePanel.removeAll();
        if (TileManager.getTile() == null) {
            return;
        }


        switch (TileManager.getTile().getZone(card).getType()) {
            case CITY:
                CityPanel panelCity = new CityPanel(TileManager.getTile().getZone(card));
                panelCity.enabledGroupOptions(false);
                zoneTypePanel.add(panelCity);
                ((TitledBorder) zoneTypePanel.getBorder()).setTitle(panelCity.getParentTitle());
                break;

            case MEADOW:
                MeadowPanel panelMeadow = new MeadowPanel(TileManager.getTile().getZone(card));
                panelMeadow.enabledGroupOptions(false);
                zoneTypePanel.add(panelMeadow);
                ((TitledBorder) zoneTypePanel.getBorder()).setTitle(panelMeadow.getParentTitle());
                break;

            case ROAD:
                RoadPanel panelRoad = new RoadPanel(TileManager.getTile().getZone(card));
                panelRoad.enabledGroupOptions(false);
                zoneTypePanel.add(panelRoad);
                ((TitledBorder) zoneTypePanel.getBorder()).setTitle(panelRoad.getParentTitle());
                break;
        }

        zoneTypePanel.repaint();
    }

    public static void main(String args[]) {


        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
//                try {
//                    UIManager.setLookAndFeel("org.pushingpixels.substance.api.skin.SubstanceBusinessBlackSteelLookAndFeel");
//                } catch (Exception ex) {
//                    Logger.getLogger(MainForm.class.getName()).log(Level.SEVERE, null, ex);
//                }

                new MainForm().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addTileButton;
    public javax.swing.JComboBox cb_east;
    public javax.swing.JComboBox cb_north;
    public javax.swing.JComboBox cb_south;
    public javax.swing.JComboBox cb_west;
    private javax.swing.JPanel connPanel;
    private javax.swing.JPanel drawPanel;
    private javax.swing.JButton jButton4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JSplitPane jSplitPane2;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JToggleButton jToggleButton1;
    public javax.swing.JPanel paramsTile;
    private javax.swing.JButton removeTileButton;
    private javax.swing.JButton resetTileButton;
    private javax.swing.JButton showEastPanel;
    private javax.swing.JButton showSouthPanel;
    private javax.swing.JButton showWestPanel;
    private javax.swing.JPanel tileSetPanel;
    private javax.swing.JTree tilesTree;
    public javax.swing.JPanel zoneTypePanel;
    // End of variables declaration//GEN-END:variables

    public void setCityPanel() {

        CityPanel cityPanel = new CityPanel();
        zoneTypePanel.add(cityPanel);
        zoneTypePanel.revalidate();
        zoneTypePanel.repaint();

    }
}
